home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 67 / IOPROG_67A.ISO / soft / Tools / mwsppv4.exe / INSERT GETHTMLTAG.SCRIPT < prev    next >
Encoding:
Text File  |  2002-09-03  |  2.2 KB  |  59 lines

  1. !!Script
  2. // Copyright ⌐ 1997-1998 - Modelworks Software
  3.  
  4. // Insert script helper for:
  5.  
  6. /**
  7. @Object: Editor 
  8. @Method: getHtmlTag(startLineIndex, startCharIndex) returns a List object containing 
  9. a list of the tag's attributes and values Each item in the list is an Association object 
  10. containing a Token object for the key and the value. Note: The first item contains the 
  11. name of the tag and has no value and the name of the list is set to the 
  12. tag name (.e.g., for the tag "<A ...>" the name is "A") The method returns null if 
  13. the specified location is not the beginning of a HTML tag (e.g., '<'). 
  14. Example: the tag "<A NAME='target'>" has the following two items in the list 
  15. item 1: Association [ Token ["A", lineIndex, charIndex], Token ["", lineIndex, charIndex]]] 
  16. item 2: Association [ Token ["NAME", lineIndex, charIndex], Token ["target", lineIndex, charIndex]]] 
  17. @Syntax: editor.getHtmlTag(startLineIndex, startCharIndex)
  18. @Example: Example: List all anchor tags in an editor with a "HREF" field
  19. var editor = getActiveEditor();
  20. var findData = editor.findFirst("<A", 0, 0, true, false, false);
  21. if (findData)
  22. {
  23.   while (findData.found)
  24.   {
  25.     var attributeList = editor.getHtmlTag(findData.range.startLineIndex, findData.range.startCharIndex);
  26.     if (attributeList)
  27.     {
  28.       var position = attributeList.getHeadPosition();
  29.       while (position.valid)
  30.       {
  31.         // attribute.key and attribute.value are Token objects
  32.         var attribute = attributeList.getNext(position);
  33.         if (attribute.key.string.toUpperCase() == "HREF")
  34.         {
  35.           var lineData = editor.copy(findData.range.startLineIndex);
  36.           output.writeMessage(editor.path, findData.range.startLineIndex, lineData);
  37.           break;
  38.         }
  39.       }
  40.     }       
  41.     editor.findNext(findData);
  42.   }
  43. }
  44. @Summary: getHtmlTag - returns a List object containing the tag's attributes
  45. */
  46.  
  47. function DoCommand()
  48. {
  49.   var editor = getActiveEditor();
  50.   if (editor)
  51.   {
  52.     var selection = editor.getSelection();
  53.     editor.replace("editor.getHtmlTag(startLineIndex, startCharIndex);", selection);
  54.     editor.setActive("Insert editor.getHtmlTag");
  55.   }
  56. }
  57.  
  58. !!/Script
  59.